package com.bdth.weget.net.bean;

import io.netty.channel.ChannelHandlerContext;

import java.net.InetSocketAddress;
import java.util.Date;

/**
 * Created by Administrator on 2019/7/11.
 */
public class ChannelStatus {
    /**
     * 链接通道
     */
    private ChannelHandlerContext ctx;
    /**
     * 最后发送报文时间
     */
    private Date lastSend;
    /**
     * 是否是坏链接
     */
    private boolean bad;

    /**
     * 错误数据包条数
     * 解析不了的数据
     */
    private int badmsg = 0;
    /**
     * 解析到的终端ID
     */
    private String simno;

    public ChannelStatus() {
    }

    public ChannelStatus(ChannelHandlerContext ctx, boolean bad, Date lastSend) {
        this.ctx = ctx;
        this.bad = bad;
        this.lastSend = lastSend;
    }

    public ChannelHandlerContext getCtx() {
        return ctx;
    }

    public void setCtx(ChannelHandlerContext ctx) {
        this.ctx = ctx;
    }

    public boolean isBad() {
        return bad;
    }

    public void setBad(boolean bad) {
        this.bad = bad;
    }

    public Date getLastSend() {
        return lastSend;
    }

    public void setLastSend(Date lastSend) {
        this.lastSend = lastSend;
    }

    public String getSimno() {
        return simno;
    }

    public void setSimno(String simno) {
        this.simno = simno;
    }

    public int getBadmsg() {
        return badmsg;
    }

    public void setBadmsg(int badmsg) {
        this.badmsg = badmsg;
    }

    @Override
    public String toString() {
        InetSocketAddress socketAddress = (InetSocketAddress)ctx.channel().remoteAddress();
        String ip = "";
        String port = "";
        if(socketAddress!=null) {
            ip = socketAddress.getAddress().getHostAddress();
            port = socketAddress.getPort() + "";
        }
        return "ChannelStatus{" +
                "ctx=[" + ip + ":" + port +
                "], lastSend=" + lastSend +
                ", bad=" + bad +
                ", badmsg=" + badmsg +
                ", simno='" + simno + '\'' +
                '}';
    }
}
